Package nz.ac.massey.softwarec.group3.actions

Source Code of nz.ac.massey.softwarec.group3.actions.GetDataTest

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nz.ac.massey.softwarec.group3.actions;

import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.Mockery;
import javax.servlet.http.HttpSession;
import nz.ac.massey.softwarec.group3.game.Game;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author wanting
*/
public class GetDataTest {
   
   private  HttpServletRequest request;
   private  HttpServletResponse response;
   private GetData getgamedata;
   private Game game;
   private HttpSession session;
   private  Mockery context;
   
    public GetDataTest() {
    }
   
    @Before
    public void setUp() {
        context=new JUnit4Mockery();
        context.setImposteriser(ClassImposteriser.INSTANCE);
        getgamedata=new GetData();

        request=context.mock(HttpServletRequest.class);
        session=context.mock(HttpSession.class);
        response=context.mock(HttpServletResponse.class);
       
        game=new Game("user@gmail.com",321);
        game.setPlaying(true);
    }
   
    @After
    public void tearDown() {
    }

    /**
     * Test of processRequest method, of class GetData.
     */
    @Test
    public void testProcessRequest() throws Exception {
        System.out.println("processRequest");
       
         context.checking(new Expectations(){
            {
               allowing(response).setContentType("text/html;charset=UTF-8");
               allowing(response).getWriter();
       
             
               one(session).getAttribute("game");
               will(returnValue(game));
            }
        });
    
         response.setContentType("text/html;charset=UTF-8");
         response.getWriter();

         //pass through the session
         game=(Game) session.getAttribute("game");
        
         assertEquals(321,game.getGameID());
        
         assertEquals("user@gmail.com",game.getCreatorEmail());
        
         assertEquals(true,game.isPlaying());
    }



    /**
     * Test of getServletInfo method, of class GetData.
     */
    @Test
    public void testGetServletInfo() {
        System.out.println("getServletInfo");
      System.out.println("getServletInfo");
       
        GetData instance = new GetData();
        String expResult = "Short description";
        String result = instance.getServletInfo();
        assertEquals(expResult, result);

    }
}
TOP

Related Classes of nz.ac.massey.softwarec.group3.actions.GetDataTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.